package com.gdou.crrp.repository;

import com.gdou.crrp.entity.Reservation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Repository
public interface ReservationRepository extends JpaRepository<Reservation, Integer> {

    List<Reservation> findByHospitalNameAndDepartmentNameAndDoctorNameAndTime(String hospitalName, String departmentName, String doctorName, Date time);

    //查找所有订单
    List<Reservation> findAll();

    //找到所有医生
    List<Reservation> findByDoctorName(String doctorName);

    //根据用户姓名与用户是否已评价找出所有的预约表(分为未评价和已评价两种)
    List<Reservation> findAllByUserNameAndIsEvaluateAndTimeLessThanAndStatus(String userName, int isEvaluate,Date time,String status, Sort sort);

    //根据预约单id查找预约单
    Reservation findById(int id);
    int countIdByUserNameAndAndIsEvaluateAndTimeLessThan(String userName,int isEvaluate,Date date);

    Page<Reservation> findAllByUserNameAndIsEvaluateAndTimeLessThan(String name, int isEvaluate,Date time,Pageable pageable);

    //根据用户名和是否评价来分页
    Page<Reservation> findAllByUserNameAndIsEvaluate(String name, int isEvaluate, Pageable pageable);

    //根据预约单id删除预约单
    @Transactional
    void deleteById(int id);

    //根据状态查找所有预约单
    List<Reservation> findAllByStatus(String status);
}
